import requests
import json
import readExcel
import unittest
import readConfig
import test_status


class test_Backscanning(unittest.TestCase):
    def setUp(self):
        pass

    def test_backscanning(self):
        url, data, headers = readExcel.read_Excel().read_excel(3)  # 根据excel用用例的函数，从0开始提交行数即可，case001就填写1
        sn = readConfig.readConfig('data', 'sn')
        token = test_status.test_Status().test_status()[0]
        auth_code = str(input("请输入正确的微信/支付宝/云闪付条码："))
        if 'sn' in data:
            if data['sn'] == '':
                data['sn'] = sn
        if 'token' in data:
            if data['token'] == '':
                data['token'] = token
        if 'auth_code' in data:
            if data['auth_code'] == '':
                data['auth_code'] = auth_code
        # 开始提交参数到接口
        # print(params)
        r1 = requests.post(url, data=data, headers=headers)
        r2 = r1.json()
        # print(json.dumps(r2, sort_keys=True, indent=4, separators=(',', ':'), ensure_ascii=False))
        self.assertEqual(r2['code'], 0)
        try:
            order_no = r2['data']['order_no']
            amount = r2['data']['trans_amt']
        except Exception:
            print(Exception)
            print(json.dumps(r2, sort_keys=True, indent=4, separators=(',', ':'), ensure_ascii=False))
        else:
            return order_no, amount

    def tearDown(self):
        pass


if __name__ == '__main__':
    unittest.main()
